package com.chunlei.check.cgproxy;

import org.springframework.cglib.core.DebuggingClassWriter;
import org.springframework.cglib.proxy.Enhancer;

/**
 * @author 朝花不迟暮
 * @version 1.0
 * @date 2020/12/4 21:50
 */
public class CgClient
{
    public static void main(String[] args)
    {
        //在指定目录下生成动态代理类
        System.setProperty(DebuggingClassWriter.DEBUG_LOCATION_PROPERTY,"E:\\JavaSpace\\chapterspace\\Character4\\CheckToken\\src\\main\\java\\com\\chunlei\\check\\cgproxy");
        Enhancer enhancer = new Enhancer();
        //继承被代理类
        enhancer.setSuperclass(HelloServiceImpl.class);
        //设置回调
        enhancer.setCallback(new HelloMethodInterceptor());
        //设置代理对象
        HelloServiceImpl helloService = (HelloServiceImpl) enhancer.create();
        helloService.sayBey();
    }
}
